#          o A B C D E F G d
matrix = [[0,1,0,0,1,0,1,0,0],# o
          [0,0,1,0,0,0,1,0,0],# A
          [0,0,0,1,0,0,0,0,0],# B
          [0,0,0,0,0,0,0,0,1],# C
          [0,0,1,0,0,1,0,0,0],# D
          [0,0,0,1,0,0,0,0,0],# E
          [0,0,0,0,0,1,0,1,0],# F
          [0,0,0,0,0,0,0,0,1]]# G

def check(line):
    if line == 8:
        global nb
        nb += 1
    else:
        col = 0
        while col <= 8:
            if matrix[line][col]:
                check(col)
            col += 1

nb = 0
check(0)
print nb




